package longrise.phone.com.bjjt_jyb.widget;



import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.Display;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.longrise.android.ILFMsgListener;

import longrise.phone.com.bjjt_jyb.R;


public class AlertDialogRecord {

	private Context context;
	private AlertDialogRecord2 dialog;
	private LinearLayout lLayout_bg;
	private Display display;
	private TextView recordTextView;

	public AlertDialogRecord(Context context) {
		this.context = context;
		WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		display = windowManager.getDefaultDisplay();
	}

	public AlertDialogRecord builder(){
		// 重写Dialog
		View view = LayoutInflater.from(context).inflate(R.layout.pub_popwindow_record, null);

		recordTextView = (TextView) view.findViewById(R.id.public_popup_text);
		lLayout_bg = (LinearLayout) view.findViewById(R.id.ll_record);

		// Dialog
		dialog = new AlertDialogRecord2(context, R.style.AlertDialogStyle);
		dialog.setContentView(view);
		dialog.setCanceledOnTouchOutside(false);		// dialog
		recordTextView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View view) {
				dialog.dismiss();
			}
		});
		lLayout_bg.setLayoutParams(new FrameLayout.LayoutParams((int) (display.getWidth() * 0.45), LayoutParams.WRAP_CONTENT));
		return this;
	}

	
	public void dismiss() {
		if(dialog.isShowing()) {					
			dialog.dismiss();
		}
	}
	
	public void show() {
		dialog.show();
	}


	public AlertDialogRecord setRecordOver(final View.OnClickListener listener) {

		if(null!=listener){
			recordTextView.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					listener.onClick(v);
					dialog.dismiss();
				}
			});
		}
		return this;
	}

}
